package com.chj.design.sk;

public class Code23_Bridge {
	public interface ITV {
		public void on();

		public void off();

		public void switchChannel(int channel);
	}

	public class SamsungTV implements ITV {
		@Override
		public void on() {
			System.out.println("Samsung is turned on.");
		}

		@Override
		public void off() {
			System.out.println("Samsung is turned off.");
		}

		@Override
		public void switchChannel(int channel) {
			System.out.println("Samsung: channel - " + channel);
		}
	}

	public static class SonyTV implements ITV {

		@Override
		public void on() {
			System.out.println("Sony is turned on.");
		}

		@Override
		public void off() {
			System.out.println("Sony is turned off.");
		}

		@Override
		public void switchChannel(int channel) {
			System.out.println("Sony: channel - " + channel);
		}
	}

	// 遥控器要包含对TV的引用
	public static abstract class AbstractRemoteControl {
		/**
		 * @uml.property name="tv"
		 * @uml.associationEnd
		 */
		private ITV tv;

		public AbstractRemoteControl(ITV tv) {
			this.tv = tv;
		}

		public void turnOn() {
			tv.on();
		}

		public void turnOff() {
			tv.off();
		}

		public void setChannel(int channel) {
			tv.switchChannel(channel);
		}
	}

	// 定义遥控器的具体类
	public static class LogitechRemoteControl extends AbstractRemoteControl {

		public LogitechRemoteControl(ITV tv) {
			super(tv);
		}

		public void setChannelKeyboard(int channel) {
			setChannel(channel);
			System.out.println("Logitech use keyword to set channel.");
		}
	}

	public static void main(String[] args) {
		ITV tv = new SonyTV();
		LogitechRemoteControl lrc = new LogitechRemoteControl(tv);
		lrc.setChannelKeyboard(100);
	}
}
